﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace Route
{
    [Serializable()]
    public class Cache
    {
        private List<Leg> _legs = new List<Leg>();

        public List<Leg> Legs
        {
            get { return _legs; }
            set { _legs = value; }
        }

        public static Cache Load(string filename)
        {
            if (!File.Exists(filename))
                return new Cache();

            Stream TestFileStream = File.OpenRead(filename);
            BinaryFormatter deserializer = new BinaryFormatter();
            Cache c = (Cache)deserializer.Deserialize(TestFileStream);
            TestFileStream.Close();
            return c;
        }

        public void Save(string filename)
        {
            File.Delete(filename);
            Stream TestFileStream = File.Create(filename);
            BinaryFormatter serializer = new BinaryFormatter();
            serializer.Serialize(TestFileStream, this);
            TestFileStream.Close();
        }
    }
}
